<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>AppScan漏洞分析</title>
		<script language="JavaScript" type="text/javascript" src="../../js/jquery.js"></script>
		<!--输入格式化 -->
		<script language="Javascript" type="text/javascript" src="edit_area/edit_area_loader.js"></script>
		<script language="Javascript" type="text/javascript">
			// initialisation
			editAreaLoader.init({
				id : "txtParameter"// id of the textarea to transform
				,
				start_highlight : true// if start with highlight
				,
				allow_resize : "both",
				allow_toggle : false,
				word_wrap : true,
				language : "zh",
				syntax : "js",
				begin_toolbar : "btn_beautifier,|",
				plugins : "beautifier",
			});

			function doRequest() {
				var url = $("#txtUrl").val();
				var method = $("#cbxMethod").val();
				var param = editAreaLoader.getValue("txtParameter");

				window.localStorage["url"] = url;
				window.localStorage["method"] = method;
				window.localStorage["param"] = param;
				param = $.trim(param);
				if(param.indexOf("{") != 0) {
					param = "{" + param + "}";
				}
				param = window.eval("(" + param + ")");

				$("#txtResult").text("");
				$.ajax({
					url : url,
					type : method,
					data : param,
					success : function(result) {
						//$("#txtResult").text(result);
						beautify(result);
					},
					error : function(event, xhr, ajaxOptions, thrownError) {
						$("#txtResult").text("请求出错");
					}
				});

			}

			/**
			 * 格式化参数
			 */
			function doFormat() {
				var paramString = editAreaLoader.getValue("txtParameter");
				if(paramString.indexOf("=") == -1) {
					return;
				}

				var pairs = paramString.split("&");
				var params, result = "";
				for(var i = 0, size = pairs.length; i < size; ++i) {
					params = pairs[i].split("=");
					if(params.length < 2)
						continue;

					if(result != "")
						result += ",\n";
					result += "\"" + params[0] + "\":\"" + params[1] + "\"";
				}

				editAreaLoader.setValue("txtParameter", result);
			}

			$(function() {
				$("#txtUrl").val(window.localStorage["url"]);
				$("#cbxMethod")[0].selectedIndex = ("POST" == window.localStorage["method"]) ? 1 : 0;
				$("#txtParameter").val(window.localStorage["param"]);
			});

		</script>
		<!--结果格式化-->
		<script src="jsbeautifier/third-party/codemirror2/lib/codemirror.js"></script>
		<script src="jsbeautifier/third-party/codemirror2/mode/javascript/javascript.js"></script>
		<link rel="stylesheet" href="jsbeautifier/third-party/codemirror2/lib/codemirror.css">
		<script src="jsbeautifier/beautify.js"></script>
		<script src="jsbeautifier/beautify-css.js"></script>
		<script src="jsbeautifier/beautify-html.js"></script>
		<script type="text/javascript">
			var the = {
				use_codemirror : (!window.location.href.match(/without-codemirror/)),
				beautify_in_progress : false,
				editor : null // codemirror editor
			};

			function beautify(source) {
				if(the.beautify_in_progress)
					return;

				the.beautify_in_progress = true;

				var opts = {
					indent_size : 1,
					indent_char : '\t',
					preserve_newlines : true,
					braces_on_own_line : false,
					keep_array_indentation : true,
					space_after_anon_function : true
				};

				var output;
				if(looks_like_html(source)) {
					output = style_html(source, opts);
				} else {
					// source = unpacker_filter(source);
					output = js_beautify(source, opts);
				}
				if(the.editor) {
					the.editor.setValue(output);
				} else {
					$('#txtResult').text(output);
				}

				the.beautify_in_progress = false;
			}

			function looks_like_html(source) {
				// <foo> - looks like html
				// <!--\nalert('foo!');\n--> - doesn't look like html

				var trimmed = source.replace(/^[ \t\n\r]+/, '');
				var comment_mark = '<' + '!-' + '-';
				return (trimmed && (trimmed.substring(0, 1) === '<' && trimmed.substring(0, 4) !== comment_mark));
			}

			$(function() {
				// the.editor = CodeMirror.fromTextArea($('#txtResult').get(0))
				// the.editor.setValue("");
			});

		</script>
	</head>
	<body>
		<h2>AppScan漏洞分析</h2>
		<fieldset>
			<legend>
				漏洞重现
			</legend>
			<div>
				目标地址
				<input id="txtUrl" style="width: 700px;height:30px" name="txtUrl" value="http://www.baidu.com">
				</input>
				，请求方式
				<select id="cbxMethod" style="width:100px">
					<option value="GET">GET</option>
					<option value="POST">POST</option>
				</select>
				<br/>
				<p>
					报文内容(JSON格式)
					<button id="btnFormat" style="width:200px;height:30px" onclick="doFormat();">
						格式化参数
					</button>
				</p>
				<textarea id="txtParameter" style="height: 150px; width: 100%;" name="txtParameter"></textarea>
			</div>
			<button id="btnRequest" style="width:100%;height:50px" onclick="javascript:doRequest();">
				发送请求
			</button>
			<p>
				结果
			</p>
			<textarea id="txtResult" style="height: 250px; width: 100%;" name="txtResult"></textarea>
		</fieldset>
	</body>
</html>
